<template>
  <div class="recommend">
    <p :style="{display: title ? title :'none'}">{{title}}<i class="iconfont icon-prev"></i></p>
    <div class="recommendList">
      <span class="recommendItem" v-for="(item,i) in Lists" :key="i">
        <img :src="item.picUrl || item.coverImgUrl" @click="turnDetail(item.id)">
        <span style="margin-top:5px">{{item.name}}</span>
        <span class="playcount">▷ {{item.playCount | simpNum}}</span>
        <span class="icon"><i class="iconfont icon-you" @click="getId(item.id)"></i></span>
      
      </span>
    </div>
    <div class="recommendList last-row">
     <span class="recommendItem" v-for="(item,i) in lastRow" :key="i">
        <img :src="item.picUrl || item.coverImgUrl" alt="" @click="turnDetail(item.id)">
        <span style="margin-top:5px">{{item.name}}</span>
        <span class="playcount">▷ {{item.playCount | simpNum}}</span>
        <span class="icon"><i class="iconfont icon-you" @click="getId(item.id)"></i></span>
      </span>
    </div>
    <el-pagination
      @current-change="handleCurrentChange"
      layout="prev, pager, next"
      :total="total"
      :page-size='50'
      v-if="total">
    </el-pagination>
  </div>
</template>

<script>
import {simpNum} from 'common/filter'
import {request} from 'network/request'
export default {
  props:{
    title:{
      default:'',
      type:String
    },
    List:{
      default:[],
      type:Array
    },
    total:{
      default:0,
      type:Number
    },
    num:{
      default:5,
      type:Number
    }
  },
  data(){
    return{
      // Lists:this.List,
      // lastrow:[]
    }
  },
  computed:{
    // handle(){
    //   let length = this.List.length
    //   if(length == 1){
    //     return true
    //   }
    //   let lastItem = this.List[length-1].length
    //   let _lastItem = this.List[length-2].length
    //   return lastItem < _lastItem
    // },
    Lists(){
      let yushu = this.List.length % this.num
      let Lists = this.List.slice()
      for(let i = 1 ; i < yushu + 1 ; i++ ){
        Lists.pop()
      }
      return Lists
    },
    lastRow(){
      let yushu = this.List.length % this.num
      let Lists = this.List
      let list = []
      for(let i = 1 ; i < yushu + 1 ; i++ ){
        list.push(Lists[Lists.length - i])
      }
      return list
    }
  },
  methods:{
    async getId(id){
      const data = await request("GET",'/playlist/detail',{id:id})
      this.$store.commit('addPlayList',data.playlist.tracks)
      localStorage.setItem('currentPlayListId',id)
    },
    turnDetail(id){
      this.$router.push('/playlistdetail/'+id+'/'+0)
    },
    handleCurrentChange(newpage){
      this.$emit('handleCurrentChange',newpage)
    }
    // changeList(){
    //   var result = []
    //   for(var i=0;i<this.List.length;i+=this.num){
    //     result.push(this.List.slice(i,i+this.num));
    //   }
    //   this.Lists = result
    //   console.log(this.Lists)
    // },
    // lastRow(){
    //   var arr1 = this.List[this.List.length - 1]
    //   var arr2 = this.List[this.List.length - 2]
    //   if(arr1 < arr2){
    //     this.lastrow = this.List[this.List.length - 1]
    //   }
    // }
  },
  // mounted(){ 
  //   this.lastRow()
  // },
  filters:{
    simpNum
  },
}
</script>

<style scoped>
.recommend p{
  font-weight: 600;
  font-size: 20px;
  color: rgb(55,55,55);
}
.recommend i{
  font-size: 19px;
}
.recommendList{
  display:flex;
  justify-content:space-between;
  flex-wrap: wrap;
}
.recommendItem{
  box-sizing: content-box;
  margin-top:15px;
  /* margin-right: 18px; */
  display: flex;
  flex-direction: column;

  max-width: 205px;
  min-width: 200px;
  max-height: 245px;
  cursor: pointer;
  /* margin-right: 20px; */
  position:relative;
  margin-bottom: 18px;
  border-radius: 5px;
  /* display: flex; */
  

  
  font-size: 15px;
  color: rgb(88, 91, 91);
  /* flex:1 */
}

.last-row{
  display: flex;
  justify-content:flex-start;
}
.last-row .recommendItem{
  margin-right: 18px;
}
/*.recommend .last-row{
  display: flex;
  justify-content: flex-start;
}
.recommend .last-row .recommendItem{
  margin-right: 23px;
} */
/* .lastRow:after{
  width: 2.5em;
} */
.recommendItem img{
  border-radius: 5px;
  width: 100%;
  height: 205px;
}
.recommendItem .playcount{
  position:absolute;
  top:0;
  right: 0;
  color: #fff;
  z-index: 9;
  font-size: 12px;
  height: 20px;
  line-height: 20px;
  padding-right: 7px;
}
.recommendItem .icon{
  opacity: 0;
  position:absolute;
  bottom:55px;
  right: 10px;
  width: 30px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  background-color: rgb(245,245,244);
  transition: all 1s ease-out;
  border-radius: 50%;
}
.recommendItem:hover .icon{
  opacity: 1;
}
.icon-you::before{
  color:rgb(236,65,65);
  font-size: 16px;
  position: relative;
  left: 1.5px;
}
</style>